package com.lkx.farmershop.controller;

import com.lkx.farmershop.common.api.ApiResult;
import com.lkx.farmershop.service.UpvoteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/upvote")
public class UpvoteController {

    @Autowired
    private UpvoteService upvoteService;

    /**
     * 点赞组团
     * @param userId
     * @param tuanId
     * @return
     */
    @Transactional
    @PostMapping("/upvote")
    public ApiResult<String> upvote(@RequestParam("userId") Long userId, @RequestParam("tuanId") Long tuanId) {
        return upvoteService.upvote(userId, tuanId);
    }

    /**
     * 判断用户是否已经点赞该团
     * @param tuanId
     * @param userId
     * @return
     */
    @GetMapping("/hasUpvote")
    public ApiResult<Boolean> hasUpvote(@RequestParam("tuanId") Long tuanId, @RequestParam("userId") Long userId) {
        return upvoteService.hasUpvote(tuanId, userId);
    }

}
